package com.selfdriving.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.selfdriving.BaseApplication;
import com.selfdriving.R;
import com.selfdriving.bean.Entity;
import com.selfdriving.bean.MyArticle;
import com.selfdriving.bean.ScenicNotes;
import com.selfdriving.view.CircularImage;

public class FeatureDiaryAdapter extends BaseAdapter
{
	private Context context;

	private List<Entity> features;

	private HolderView holderView;
	BaseApplication application;
	int flag;

	public FeatureDiaryAdapter(BaseApplication application, Context context,
			List<Entity> features, int flag)
	{
		this.flag = flag;
		this.application = application;
		this.context = context;
		this.features = features;
	}

	@Override
	public int getCount()
	{
		return features.size();
	}

	@Override
	public Object getItem(int poistion)
	{
		return features.get(poistion);
	}

	@Override
	public long getItemId(int poistion)
	{
		return poistion;
	}

	@Override
	public View getView(int poistion, View view, ViewGroup arg2)
	{
		if (view == null)
		{
			holderView = new HolderView();
			view = ((LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
					.inflate(R.layout.feature_diary_item, null);
			view.setTag(holderView);
		} else
		{
			holderView = (HolderView) view.getTag();
		}
		holderView.icon = (CircularImage) view.findViewById(R.id.ivIcon);
		holderView.img = (ImageView) view.findViewById(R.id.ivBigImg);
		holderView.title = (TextView) view.findViewById(R.id.title);
		holderView.name = (TextView) view.findViewById(R.id.featrue_name);
		holderView.content = (TextView) view.findViewById(R.id.content);
		holderView.time = (TextView) view.findViewById(R.id.time);
		holderView.love = (TextView) view
				.findViewById(R.id.comment_button_text);
		holderView.title = (TextView) view.findViewById(R.id.title);
		if (flag == 0)
		{
			MyArticle feature = (MyArticle) features.get(poistion);
			holderView.title.setText(feature.getTitle());
			holderView.content.setVisibility(View.GONE);
			holderView.time.setText(feature.getTimes());
			holderView.love.setText(feature.getReview());
			holderView.icon.setVisibility(View.GONE);
			holderView.name.setVisibility(View.GONE);
			application.imageLoader.displayImage(feature.getImg(),
					holderView.img, application.options);
		} else if (flag == 1)
		{
			holderView.content.setVisibility(View.VISIBLE);
			holderView.icon.setVisibility(View.VISIBLE);
			holderView.name.setVisibility(View.VISIBLE);
			ScenicNotes scenic = (ScenicNotes) features.get(poistion);
			holderView.title.setText(scenic.getTitle());
			holderView.content.setText(scenic.getContent());
			holderView.time.setText(scenic.getTime());
			holderView.love.setText(scenic.getReviewSize());
			application.imageLoader.displayImage(scenic.getImg(),
					holderView.img, application.options);
			application.imageLoader.displayImage(scenic.getHeadImg(),
					holderView.icon, application.options);
		}
		return view;
	}

	private class HolderView
	{
		private CircularImage icon;

		private ImageView img;

		private TextView title;

		private TextView name;

		private TextView content;

		private TextView time;

		private TextView love;
	}

}
